package com.shujia;

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

public class WordCountJava {
    public static void main(String[] args) throws IOException {

        BufferedReader bufferedReader = new BufferedReader(new FileReader("scala_code/data/words.txt"));
        HashMap<String, Integer> wordNum = new HashMap<>();

        String line = "";
        while ((line = bufferedReader.readLine())!=null){
            String[] splits = line.split(" ");
            for (String word : splits) {
                Integer num = wordNum.getOrDefault(word, 0);
                num += 1;
                wordNum.put(word,num);
            }

        }
        for (Map.Entry<String, Integer> stringIntegerEntry : wordNum.entrySet()) {
            System.out.println(stringIntegerEntry);
        }

        bufferedReader.close();
    }
}
